package com.cz.nongyetongv5.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;

import com.cz.nongyetongv5.R;
import com.cz.nongyetongv5.adapter.IconGrideAdapter;
import com.cz.nongyetongv5.application.InitApplication;
import com.cz.nongyetongv5.bean.User;

public class GengDuoActivity extends Fragment implements View.OnClickListener {

	// 更多页面的图标菜单
	private GridView gvGengDuoMenu = null;

	/**
	 * 适配器
	 */
	private IconGrideAdapter adapter = null;

	/**
	 *
	 * 数据
	 */
	private List<Map<String, Object>> datas = null;

	private User user;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
							 Bundle savedInstanceState) {

		return inflater.inflate(R.layout.gengduo, null);
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);

		Activity activity = getActivity();

		gvGengDuoMenu = (GridView) activity.findViewById(R.id.gvGengDuoMenu);

		datas = new ArrayList<Map<String, Object>>();

		// 意见反馈的数据
		Map<String, Object> icon_fankui = new HashMap<String, Object>();

		icon_fankui.put("ibIconItem", R.drawable.fankui_icon);
		icon_fankui.put("tvIconItem", "意见反馈");

		datas.add(icon_fankui);

		Map<String, Object> icon_banben = new HashMap<String, Object>();

		icon_banben.put("ibIconItem", R.drawable.banben_icon);
		icon_banben.put("tvIconItem", "版本信息");

		InitApplication application = (InitApplication) getActivity()
				.getApplicationContext();

		icon_banben.put("version", application.hasNewVersion());

		datas.add(icon_banben);

		adapter = new IconGrideAdapter(getActivity(), datas,
				activity.getLayoutInflater(), this);

		gvGengDuoMenu.setAdapter(adapter);

		user = (User) getActivity().getIntent().getSerializableExtra("user");

	}

	@Override
	public void onClick(View v) {

		int postion = gvGengDuoMenu.getPositionForView(v);

		// 点击了意见反馈
		if (postion == 0) {
			Intent intent_tofankui = new Intent(
					GengDuoActivity.this.getActivity(),
					YiJianFanKuiActivity.class);

			intent_tofankui.putExtra("user", user);

			startActivity(intent_tofankui);

		} else if (postion == 1) {
			// 点击了版本信息'
			Intent intent_tobanbenxinxi = new Intent(
					GengDuoActivity.this.getActivity(),
					BanBenXinxiActivity.class);

			intent_tobanbenxinxi.putExtra("user", user);

			startActivity(intent_tobanbenxinxi);

		}

	}

}
